using System.Threading.Tasks;
using JoyfulHomeJourney.BackEnd.Infrastructure.Dtos.Requests.Objects;
using JoyfulHomeJourney.BackEnd.Server.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace JoyfulHomeJourney.BackEnd.Api.Admin.Controllers
{
	public class EmployeesController : BaseController
	{
		private readonly IEmployeesServer _employeesServer;
		public EmployeesController(IEmployeesServer employeesServer)
		{
			_employeesServer = employeesServer;
		}
		/// <summary>
		/// 添加
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "carShop" })]
        public async Task<IActionResult> Add(RequestEmployeesDto dto)
		{
			dto.carShopId = _account.AId;
            return Send(await _employeesServer.AddAsync(dto));
		}
		/// <summary>
		/// 删除
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<IActionResult> Delete(RequestEmployeesDto dto)
		{
			return Send(await _employeesServer.DeleteAsync(dto));
		}
		/// <summary>
		/// 修改
		/// </summary>
		/// <param name="dto"></param>
		/// <returns></returns>
		[HttpPost]
		public async Task<IActionResult> Update(RequestEmployeesDto dto)
		{
			return Send(await _employeesServer.UpdateAsync(dto));
		}
		/// <summary>
		/// 分页
		/// </summary>
		/// <param name="page"></param>
		/// <param name="limit"></param>
		/// <returns></returns>
		[HttpGet]
		public async Task<IActionResult> Pagination(int page,int limit)
		{
			return Send(await _employeesServer.PaginationAsync(page,limit));
		}
        /// <summary>
        /// 获取员工名称
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "employee" })]
        public async Task<IActionResult> Get_em_name(string uid)
        {
            return Send(await _employeesServer.Get_em_name(uid));
        }
        /// <summary>
        /// 获取汽车店员工消息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "carShop" })]
        public async Task<IActionResult> Get_employ(int page, int limit,string key)
        {
			string uid = _account.AId;
            return Send(await _employeesServer.Get_employ(page, limit, key,uid));
        }
    }
}
